package com.ruoyi.usermodule.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.usermodule.domain.FangAdmin;
import com.ruoyi.usermodule.service.IFangAdminService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户表Controller
 * 
 * @author ruoyi
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/adminList")
public class FangAdminController extends BaseController
{
    @Autowired
    private IFangAdminService fangAdminService;

    /**
     * 查询用户表列表
     */
    @RequiresPermissions("usermodule:adminList:list")
    @GetMapping("/list")
    public TableDataInfo list(FangAdmin fangAdmin)
    {
        startPage();
        List<FangAdmin> list = fangAdminService.selectFangAdminList(fangAdmin);
        return getDataTable(list);
    }

    @GetMapping("/listAdmin")
    public TableDataInfo listAdmin(FangAdmin fangAdmin)
    {
        startPage();
        List<FangAdmin> list = fangAdminService.selectFanglistAdmin(fangAdmin);
        return getDataTable(list);
    }


    /**
     * 导出用户表列表
     */
    @RequiresPermissions("usermodule:adminList:export")
    @Log(title = "用户表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FangAdmin fangAdmin)
    {
        List<FangAdmin> list = fangAdminService.selectFangAdminList(fangAdmin);
        ExcelUtil<FangAdmin> util = new ExcelUtil<FangAdmin>(FangAdmin.class);
        util.exportExcel(response, list, "用户表数据");
    }

    /**
     * 获取用户表详细信息
     */
    @RequiresPermissions("usermodule:adminList:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(fangAdminService.selectFangAdminById(id));
    }

    /**
     * 新增用户表
     */
    @RequiresPermissions("usermodule:adminList:add")
    @Log(title = "用户表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FangAdmin fangAdmin)
    {
        return toAjax(fangAdminService.insertFangAdmin(fangAdmin));
    }

    /**
     * 修改用户表
     */
    @RequiresPermissions("usermodule:adminList:edit")
    @Log(title = "用户表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FangAdmin fangAdmin)
    {
        return toAjax(fangAdminService.updateFangAdmin(fangAdmin));
    }

    /**
     * 删除用户表
     */
    @RequiresPermissions("usermodule:adminList:remove")
    @Log(title = "用户表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(fangAdminService.deleteFangAdminByIds(ids));
    }
}
